import { Filter,GlProgram} from "pixi.js";
import vertex from '@/filters/defaultFilter.vert?raw'
import fragment from '@/filters/Tone/Tone.frag?raw'

export class ToneFilter extends Filter{
    constructor(){
        super({
            glProgram:new GlProgram({
                vertex,
                fragment
            }),
            resources:{
                toneUniforms:{
                    tone:{
                        value:[0,0,0],
                        type:'vec3<f32>'
                    }
                }
            }
        });
    }

    set red(r){
        this.resources.toneUniforms.uniforms.tone[0]=r;
    }
    set green(g){
        this.resources.toneUniforms.uniforms.tone[1]=g;
    }
    set blue(b){
        this.resources.toneUniforms.uniforms.tone[2]=b;
    }

    get tone(){
        return this.resources.toneUniforms.uniforms.tone;
    }

    get red(){
        return this.resources.toneUniforms.uniforms.tone[0];
    }

    get green(){
        return this.resources.toneUniforms.uniforms.tone[1];
    }

    get blue(){
        return this.resources.toneUniforms.uniforms.tone[2];
    }

    set tone(arr){
        this.setTone(...arr);
    }

    setTone(r,g,b){
        let uniforms=this.resources.toneUniforms.uniforms;
        uniforms.tone[0]=r;
        uniforms.tone[1]=g;
        uniforms.tone[2]=b;
    }
}